<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>bfsNet: Fichero Fuente /Users/nicolunacba/Development/Dinic/trunk/network/hashtbl.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Generado por Doxygen 1.7.4 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Buscar');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="bfs-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">bfsNet&#160;<span id="projectnumber">1.0</span></div>
   <div id="projectbrief">Algoritmo BFS para encontrar un camino de fuente a destino en una Network</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Página&#160;principal</span></a></li>
      <li><a href="annotated.html"><span>Estructuras&#160;de&#160;Datos</span></a></li>
      <li class="current"><a href="files.html"><span>Archivos</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Buscar" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>Lista&#160;de&#160;archivos</span></a></li>
      <li><a href="globals.html"><span>Globales</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('hashtbl_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">/Users/nicolunacba/Development/Dinic/trunk/network/hashtbl.c</div>  </div>
</div>
<div class="contents">
<a href="hashtbl_8c.html">Ir a la documentación de este archivo.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2011 the authors listed at the following URL, and/or</span>
<a name="l00002"></a>00002 <span class="comment">the authors of referenced articles or incorporated external code:</span>
<a name="l00003"></a>00003 <span class="comment">http://en.literateprograms.org/Hash_table_(C)?action=history&amp;offset=20100620072342</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">Permission is hereby granted, free of charge, to any person obtaining</span>
<a name="l00006"></a>00006 <span class="comment">a copy of this software and associated documentation files (the</span>
<a name="l00007"></a>00007 <span class="comment">&quot;Software&quot;), to deal in the Software without restriction, including</span>
<a name="l00008"></a>00008 <span class="comment">without limitation the rights to use, copy, modify, merge, publish,</span>
<a name="l00009"></a>00009 <span class="comment">distribute, sublicense, and/or sell copies of the Software, and to</span>
<a name="l00010"></a>00010 <span class="comment">permit persons to whom the Software is furnished to do so, subject to</span>
<a name="l00011"></a>00011 <span class="comment">the following conditions:</span>
<a name="l00012"></a>00012 <span class="comment"></span>
<a name="l00013"></a>00013 <span class="comment">The above copyright notice and this permission notice shall be</span>
<a name="l00014"></a>00014 <span class="comment">included in all copies or substantial portions of the Software.</span>
<a name="l00015"></a>00015 <span class="comment"></span>
<a name="l00016"></a>00016 <span class="comment">THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,</span>
<a name="l00017"></a>00017 <span class="comment">EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF</span>
<a name="l00018"></a>00018 <span class="comment">MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.</span>
<a name="l00019"></a>00019 <span class="comment">IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY</span>
<a name="l00020"></a>00020 <span class="comment">CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,</span>
<a name="l00021"></a>00021 <span class="comment">TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE</span>
<a name="l00022"></a>00022 <span class="comment">SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</span>
<a name="l00023"></a>00023 <span class="comment"></span>
<a name="l00024"></a>00024 <span class="comment">Retrieved from: http://en.literateprograms.org/Hash_table_(C)?oldid=16749</span>
<a name="l00025"></a>00025 <span class="comment">*/</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#include &quot;<a class="code" href="hashtbl_8h.html">hashtbl.h</a>&quot;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;<a class="code" href="list_8h.html">list.h</a>&quot;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="keyword">static</span> <span class="keywordtype">char</span> *mystrdup(<span class="keyword">const</span> <span class="keywordtype">char</span> *s)
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034         <span class="keywordtype">char</span> *b;
<a name="l00035"></a>00035         <span class="keywordflow">if</span>(!(b=malloc(strlen(s)+1))) <span class="keywordflow">return</span> NULL;
<a name="l00036"></a>00036         strcpy(b, s);
<a name="l00037"></a>00037         <span class="keywordflow">return</span> b;
<a name="l00038"></a>00038 }
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="keyword">static</span> <a class="code" href="hashtbl_8h.html#a0e1e919c9c3e5da2862baf08fa7f9e28">hash_size</a> def_hashfunc(<span class="keyword">const</span> <span class="keywordtype">char</span> *key)
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043         <a class="code" href="hashtbl_8h.html#a0e1e919c9c3e5da2862baf08fa7f9e28">hash_size</a> hash=0;
<a name="l00044"></a>00044         
<a name="l00045"></a>00045         <span class="keywordflow">while</span>(*key) hash+=(<span class="keywordtype">unsigned</span> char)*key++;
<a name="l00046"></a>00046 
<a name="l00047"></a>00047         <span class="keywordflow">return</span> hash;
<a name="l00048"></a>00048 }
<a name="l00049"></a>00049 
<a name="l00050"></a>00050 
<a name="l00052"></a><a class="code" href="hashtbl_8h.html#aa7e342f8612905f6d59e444d82b52954">00052</a> <a class="code" href="structhashtbl.html">HASHTBL</a> *<a class="code" href="hashtbl_8c.html#aa7e342f8612905f6d59e444d82b52954">hashtbl_create</a>(<a class="code" href="hashtbl_8h.html#a0e1e919c9c3e5da2862baf08fa7f9e28">hash_size</a> <a class="code" href="structs_b_f_s.html#ae9f51f5758591221e7f66f863b4f30a7">size</a>, <a class="code" href="hashtbl_8h.html#a0e1e919c9c3e5da2862baf08fa7f9e28">hash_size</a> (*hashfunc)(<span class="keyword">const</span> <span class="keywordtype">char</span> *))
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054         <a class="code" href="structhashtbl.html">HASHTBL</a> *<a class="code" href="structhashtbl.html">hashtbl</a>;
<a name="l00055"></a>00055 
<a name="l00056"></a>00056         <span class="keywordflow">if</span>(!(hashtbl=malloc(<span class="keyword">sizeof</span>(<a class="code" href="structhashtbl.html">HASHTBL</a>)))) <span class="keywordflow">return</span> NULL;
<a name="l00057"></a>00057 
<a name="l00058"></a>00058         <span class="keywordflow">if</span>(!(hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>=calloc(size, <span class="keyword">sizeof</span>(<span class="keyword">struct</span> <a class="code" href="structhashnode__s.html">hashnode_s</a>*)))) {
<a name="l00059"></a>00059                 free(hashtbl);
<a name="l00060"></a>00060                 <span class="keywordflow">return</span> NULL;
<a name="l00061"></a>00061         }
<a name="l00062"></a>00062 
<a name="l00063"></a>00063         hashtbl-&gt;<a class="code" href="structhashtbl.html#a1b34d3db5a62a9a55a554689a6a8234e">size</a>=<a class="code" href="structs_b_f_s.html#ae9f51f5758591221e7f66f863b4f30a7">size</a>;
<a name="l00064"></a>00064 
<a name="l00065"></a>00065         <span class="keywordflow">if</span>(hashfunc) hashtbl-&gt;<a class="code" href="structhashtbl.html#afa90606d4ebad0d4cba6602e6f3161cb">hashfunc</a>=hashfunc;
<a name="l00066"></a>00066         <span class="keywordflow">else</span> hashtbl-&gt;<a class="code" href="structhashtbl.html#afa90606d4ebad0d4cba6602e6f3161cb">hashfunc</a>=def_hashfunc;
<a name="l00067"></a>00067 
<a name="l00068"></a>00068         <span class="keywordflow">return</span> hashtbl;
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070 
<a name="l00071"></a>00071 <span class="comment">/* Added data destructor */</span>
<a name="l00073"></a><a class="code" href="hashtbl_8h.html#a4c57259cd505c293809adf10fa98cd7a">00073</a> <span class="keywordtype">void</span> <a class="code" href="hashtbl_8c.html#a4c57259cd505c293809adf10fa98cd7a">hashtbl_destroy</a>(<a class="code" href="structhashtbl.html">HASHTBL</a> *<a class="code" href="structhashtbl.html">hashtbl</a>)
<a name="l00074"></a>00074 {
<a name="l00075"></a>00075         <a class="code" href="hashtbl_8h.html#a0e1e919c9c3e5da2862baf08fa7f9e28">hash_size</a> n;
<a name="l00076"></a>00076         <span class="keyword">struct </span><a class="code" href="structhashnode__s.html">hashnode_s</a> *node, *oldnode;
<a name="l00077"></a>00077         
<a name="l00078"></a>00078 
<a name="l00079"></a>00079         <span class="keywordflow">for</span>(n=0; n&lt;hashtbl-&gt;<a class="code" href="structhashtbl.html#a1b34d3db5a62a9a55a554689a6a8234e">size</a>; ++n) {
<a name="l00080"></a>00080                 node=hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>[n];
<a name="l00081"></a>00081                 <span class="keywordflow">while</span>(node) {
<a name="l00082"></a>00082                         free(node-&gt;<a class="code" href="structhashnode__s.html#a5892a9181e6a332f84d27aecd41dcd12">key</a>);
<a name="l00083"></a>00083                         <a class="code" href="list_8c.html#afb09d6d07cbb6e7ae2318a0aa4f6e875">list_destroy</a>(node-&gt;<a class="code" href="structhashnode__s.html#a735984d41155bc1032e09bece8f8d66d">data</a>); <span class="comment">/* Derrota personal por no poder implementar</span>
<a name="l00084"></a>00084 <span class="comment">                                       * punteros a funciones :&#39;(</span>
<a name="l00085"></a>00085 <span class="comment">                                       */</span>
<a name="l00086"></a>00086                         oldnode=node;
<a name="l00087"></a>00087                         node=node-&gt;<a class="code" href="structhashnode__s.html#aabb745bae27cc9bf27db56c5c56e9f39">next</a>;
<a name="l00088"></a>00088                         free(oldnode);
<a name="l00089"></a>00089                 }
<a name="l00090"></a>00090         }
<a name="l00091"></a>00091         free(hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>);
<a name="l00092"></a>00092         free(hashtbl);
<a name="l00093"></a>00093 }
<a name="l00094"></a>00094 
<a name="l00096"></a><a class="code" href="hashtbl_8h.html#a6b2853739dee3d59dcca062d62ac4600">00096</a> <span class="keywordtype">int</span> <a class="code" href="hashtbl_8c.html#a6b2853739dee3d59dcca062d62ac4600">hashtbl_insert</a>(<a class="code" href="structhashtbl.html">HASHTBL</a> *<a class="code" href="structhashtbl.html">hashtbl</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> *key, <span class="keywordtype">void</span> *<a class="code" href="structhashnode__s.html#a735984d41155bc1032e09bece8f8d66d">data</a>)
<a name="l00097"></a>00097 {
<a name="l00098"></a>00098         <span class="keyword">struct </span><a class="code" href="structhashnode__s.html">hashnode_s</a> *node;
<a name="l00099"></a>00099         <a class="code" href="hashtbl_8h.html#a0e1e919c9c3e5da2862baf08fa7f9e28">hash_size</a> hash=hashtbl-&gt;<a class="code" href="structhashtbl.html#afa90606d4ebad0d4cba6602e6f3161cb">hashfunc</a>(key)%hashtbl-&gt;<a class="code" href="structhashtbl.html#a1b34d3db5a62a9a55a554689a6a8234e">size</a>;
<a name="l00100"></a>00100 
<a name="l00101"></a>00101 
<a name="l00102"></a>00102 <span class="comment">/*      fprintf(stderr, &quot;hashtbl_insert() key=%s, hash=%d, data=%s\n&quot;, key, hash, (char*)data);*/</span>
<a name="l00103"></a>00103 
<a name="l00104"></a>00104         node=hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>[hash];
<a name="l00105"></a>00105         <span class="keywordflow">while</span>(node) {
<a name="l00106"></a>00106                 <span class="keywordflow">if</span>(!strcmp(node-&gt;<a class="code" href="structhashnode__s.html#a5892a9181e6a332f84d27aecd41dcd12">key</a>, key)) {
<a name="l00107"></a>00107                         node-&gt;<a class="code" href="structhashnode__s.html#a735984d41155bc1032e09bece8f8d66d">data</a>=<a class="code" href="structhashnode__s.html#a735984d41155bc1032e09bece8f8d66d">data</a>;
<a name="l00108"></a>00108                         <span class="keywordflow">return</span> 0;
<a name="l00109"></a>00109                 }
<a name="l00110"></a>00110                 node=node-&gt;<a class="code" href="structhashnode__s.html#aabb745bae27cc9bf27db56c5c56e9f39">next</a>;
<a name="l00111"></a>00111         }
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 
<a name="l00114"></a>00114         <span class="keywordflow">if</span>(!(node=malloc(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> <a class="code" href="structhashnode__s.html">hashnode_s</a>)))) <span class="keywordflow">return</span> -1;
<a name="l00115"></a>00115         <span class="keywordflow">if</span>(!(node-&gt;<a class="code" href="structhashnode__s.html#a5892a9181e6a332f84d27aecd41dcd12">key</a>=mystrdup(key))) {
<a name="l00116"></a>00116                 free(node);
<a name="l00117"></a>00117                 <span class="keywordflow">return</span> -1;
<a name="l00118"></a>00118         }
<a name="l00119"></a>00119         node-&gt;<a class="code" href="structhashnode__s.html#a735984d41155bc1032e09bece8f8d66d">data</a>=<a class="code" href="structhashnode__s.html#a735984d41155bc1032e09bece8f8d66d">data</a>;
<a name="l00120"></a>00120         node-&gt;<a class="code" href="structhashnode__s.html#aabb745bae27cc9bf27db56c5c56e9f39">next</a>=hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>[hash];
<a name="l00121"></a>00121         hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>[hash]=node;
<a name="l00122"></a>00122 
<a name="l00123"></a>00123 
<a name="l00124"></a>00124         <span class="keywordflow">return</span> 0;
<a name="l00125"></a>00125 }
<a name="l00126"></a>00126 
<a name="l00128"></a><a class="code" href="hashtbl_8h.html#a5e5873b1bc7ddb5cf6d279205eaf64ff">00128</a> <span class="keywordtype">int</span> <a class="code" href="hashtbl_8c.html#a5e5873b1bc7ddb5cf6d279205eaf64ff">hashtbl_remove</a>(<a class="code" href="structhashtbl.html">HASHTBL</a> *<a class="code" href="structhashtbl.html">hashtbl</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> *key)
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130         <span class="keyword">struct </span><a class="code" href="structhashnode__s.html">hashnode_s</a> *node, *prevnode=NULL;
<a name="l00131"></a>00131         <a class="code" href="hashtbl_8h.html#a0e1e919c9c3e5da2862baf08fa7f9e28">hash_size</a> hash=hashtbl-&gt;<a class="code" href="structhashtbl.html#afa90606d4ebad0d4cba6602e6f3161cb">hashfunc</a>(key)%hashtbl-&gt;<a class="code" href="structhashtbl.html#a1b34d3db5a62a9a55a554689a6a8234e">size</a>;
<a name="l00132"></a>00132 
<a name="l00133"></a>00133         node=hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>[hash];
<a name="l00134"></a>00134         <span class="keywordflow">while</span>(node) {
<a name="l00135"></a>00135                 <span class="keywordflow">if</span>(!strcmp(node-&gt;<a class="code" href="structhashnode__s.html#a5892a9181e6a332f84d27aecd41dcd12">key</a>, key)) {
<a name="l00136"></a>00136                         free(node-&gt;<a class="code" href="structhashnode__s.html#a5892a9181e6a332f84d27aecd41dcd12">key</a>);
<a name="l00137"></a>00137                         <span class="keywordflow">if</span>(prevnode) prevnode-&gt;<a class="code" href="structhashnode__s.html#aabb745bae27cc9bf27db56c5c56e9f39">next</a>=node-&gt;<a class="code" href="structhashnode__s.html#aabb745bae27cc9bf27db56c5c56e9f39">next</a>;
<a name="l00138"></a>00138                         <span class="keywordflow">else</span> hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>[hash]=node-&gt;<a class="code" href="structhashnode__s.html#aabb745bae27cc9bf27db56c5c56e9f39">next</a>;
<a name="l00139"></a>00139                         free(node);
<a name="l00140"></a>00140                         <span class="keywordflow">return</span> 0;
<a name="l00141"></a>00141                 }
<a name="l00142"></a>00142                 prevnode=node;
<a name="l00143"></a>00143                 node=node-&gt;<a class="code" href="structhashnode__s.html#aabb745bae27cc9bf27db56c5c56e9f39">next</a>;
<a name="l00144"></a>00144         }
<a name="l00145"></a>00145 
<a name="l00146"></a>00146         <span class="keywordflow">return</span> -1;
<a name="l00147"></a>00147 }
<a name="l00148"></a>00148 
<a name="l00150"></a><a class="code" href="hashtbl_8h.html#a09a188d83a55ba59116a7c301c032a68">00150</a> <span class="keywordtype">void</span> *<a class="code" href="hashtbl_8c.html#a09a188d83a55ba59116a7c301c032a68">hashtbl_get</a>(<a class="code" href="structhashtbl.html">HASHTBL</a> *<a class="code" href="structhashtbl.html">hashtbl</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> *key)
<a name="l00151"></a>00151 {
<a name="l00152"></a>00152         <span class="keyword">struct </span><a class="code" href="structhashnode__s.html">hashnode_s</a> *node;
<a name="l00153"></a>00153         <a class="code" href="hashtbl_8h.html#a0e1e919c9c3e5da2862baf08fa7f9e28">hash_size</a> hash=hashtbl-&gt;<a class="code" href="structhashtbl.html#afa90606d4ebad0d4cba6602e6f3161cb">hashfunc</a>(key)%hashtbl-&gt;<a class="code" href="structhashtbl.html#a1b34d3db5a62a9a55a554689a6a8234e">size</a>;
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 <span class="comment">/*      fprintf(stderr, &quot;hashtbl_get() key=%s, hash=%d\n&quot;, key, hash);*/</span>
<a name="l00156"></a>00156 
<a name="l00157"></a>00157         node=hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>[hash];
<a name="l00158"></a>00158         <span class="keywordflow">while</span>(node) {
<a name="l00159"></a>00159                 <span class="keywordflow">if</span>(!strcmp(node-&gt;<a class="code" href="structhashnode__s.html#a5892a9181e6a332f84d27aecd41dcd12">key</a>, key)) <span class="keywordflow">return</span> node-&gt;<a class="code" href="structhashnode__s.html#a735984d41155bc1032e09bece8f8d66d">data</a>;
<a name="l00160"></a>00160                 node=node-&gt;<a class="code" href="structhashnode__s.html#aabb745bae27cc9bf27db56c5c56e9f39">next</a>;
<a name="l00161"></a>00161         }
<a name="l00162"></a>00162         <span class="keywordflow">return</span> NULL;
<a name="l00163"></a>00163 }
<a name="l00164"></a>00164 
<a name="l00166"></a><a class="code" href="hashtbl_8h.html#a460651cb9ee95096d0a37ad691b8966c">00166</a> <span class="keywordtype">int</span> <a class="code" href="hashtbl_8c.html#a460651cb9ee95096d0a37ad691b8966c">hashtbl_resize</a>(<a class="code" href="structhashtbl.html">HASHTBL</a> *<a class="code" href="structhashtbl.html">hashtbl</a>, <a class="code" href="hashtbl_8h.html#a0e1e919c9c3e5da2862baf08fa7f9e28">hash_size</a> size)
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168         <a class="code" href="structhashtbl.html">HASHTBL</a> newtbl;
<a name="l00169"></a>00169         <a class="code" href="hashtbl_8h.html#a0e1e919c9c3e5da2862baf08fa7f9e28">hash_size</a> n;
<a name="l00170"></a>00170         <span class="keyword">struct </span><a class="code" href="structhashnode__s.html">hashnode_s</a> *node,*<a class="code" href="structhashnode__s.html#aabb745bae27cc9bf27db56c5c56e9f39">next</a>;
<a name="l00171"></a>00171 
<a name="l00172"></a>00172         newtbl.<a class="code" href="structhashtbl.html#a1b34d3db5a62a9a55a554689a6a8234e">size</a>=size;
<a name="l00173"></a>00173         newtbl.<a class="code" href="structhashtbl.html#afa90606d4ebad0d4cba6602e6f3161cb">hashfunc</a>=hashtbl-&gt;<a class="code" href="structhashtbl.html#afa90606d4ebad0d4cba6602e6f3161cb">hashfunc</a>;
<a name="l00174"></a>00174         
<a name="l00175"></a>00175         <span class="keywordflow">if</span>(!(newtbl.<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>=calloc(size, <span class="keyword">sizeof</span>(<span class="keyword">struct</span> <a class="code" href="structhashnode__s.html">hashnode_s</a>*)))) <span class="keywordflow">return</span> -1;
<a name="l00176"></a>00176 
<a name="l00177"></a>00177         <span class="keywordflow">for</span>(n=0; n&lt;hashtbl-&gt;<a class="code" href="structhashtbl.html#a1b34d3db5a62a9a55a554689a6a8234e">size</a>; ++n) {
<a name="l00178"></a>00178                 <span class="keywordflow">for</span>(node=hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>[n]; node; node=next) {
<a name="l00179"></a>00179                         next = node-&gt;<a class="code" href="structhashnode__s.html#aabb745bae27cc9bf27db56c5c56e9f39">next</a>;
<a name="l00180"></a>00180                         <a class="code" href="hashtbl_8c.html#a6b2853739dee3d59dcca062d62ac4600">hashtbl_insert</a>(&amp;newtbl, node-&gt;<a class="code" href="structhashnode__s.html#a5892a9181e6a332f84d27aecd41dcd12">key</a>, node-&gt;<a class="code" href="structhashnode__s.html#a735984d41155bc1032e09bece8f8d66d">data</a>);
<a name="l00181"></a>00181                         <a class="code" href="hashtbl_8c.html#a5e5873b1bc7ddb5cf6d279205eaf64ff">hashtbl_remove</a>(hashtbl, node-&gt;<a class="code" href="structhashnode__s.html#a5892a9181e6a332f84d27aecd41dcd12">key</a>);
<a name="l00182"></a>00182                         
<a name="l00183"></a>00183                 }
<a name="l00184"></a>00184         }
<a name="l00185"></a>00185 
<a name="l00186"></a>00186         free(hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>);
<a name="l00187"></a>00187         hashtbl-&gt;<a class="code" href="structhashtbl.html#a1b34d3db5a62a9a55a554689a6a8234e">size</a>=newtbl.<a class="code" href="structhashtbl.html#a1b34d3db5a62a9a55a554689a6a8234e">size</a>;
<a name="l00188"></a>00188         hashtbl-&gt;<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>=newtbl.<a class="code" href="structhashtbl.html#ad211d1fc97e38c179b3906954ba750fd">nodes</a>;
<a name="l00189"></a>00189 
<a name="l00190"></a>00190         <span class="keywordflow">return</span> 0;
<a name="l00191"></a>00191 }
<a name="l00192"></a>00192 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="hashtbl_8c.html">hashtbl.c</a>      </li>
      <li class="footer">Generado el Miércoles, 13 de Abril de 2011 20:34:14 para bfsNet por&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>Todo</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Estructuras de Datos</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Archivos</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Funciones</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>&apos;typedefs&apos;</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>&apos;defines&apos;</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


</body>
</html>
